<template>
  <el-container>
    <el-header style="height: 47px;">
      <p>数据报表</p>
    </el-header>
    <el-main>
      <el-row class="btn-group">
      <el-button  class="btn"  @click="addData"><span>导出</span> <i class="el-icon-download"></i>
      </el-button>
      </el-row>
      <el-table style="height: 100%"
                v-loading="loading"
                element-loading-text="给我一点时间"
                @selection-change="selectDatas"
                @row-dblclick = "dbClick">
        <el-table-column sortable align="center" prop="standard_name" label="车场名称"></el-table-column>
        <el-table-column sortable align="center" prop="createorgname" label="位置" ></el-table-column>
        <el-table-column sortable align="center" prop="useorgs" label="经营单位" ></el-table-column>
        <el-table-column sortable align="center" prop="standard_sdate" label="上报入场次数"></el-table-column>
        <el-table-column sortable align="center" prop="standard_edate" label="上报出场次数" ></el-table-column>
        <el-table-column sortable align="center" prop="standard_blur" label="入场顺差" ></el-table-column>
        <el-table-column sortable align="center" prop="standard_free" label="上报泊位剩余次数" ></el-table-column>
        <el-table-column fixed="right" align="center" width="70" label="操作">
          <template slot-scope="scope">
            <el-dropdown trigger="click" @command="handleCommand">
              <el-button class="btn-drop-down" @click="selectRow(scope.row)">
                <i class="el-icon-arrow-down"></i>
              </el-button>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item command="edit">编辑</el-dropdown-item>
                <el-dropdown-item command="del">删除</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </template>
        </el-table-column>
      </el-table>
    </el-main>
    <el-footer>
      <el-pagination
        background
        layout="total,sizes,prev,pager,next,jumper"
        :total="dataCount"
        :page-sizes="[10,20,30,50]"
        :page-size="dataPageSize"
        @current-change="handleCurrentChange"
        @size-change="handleSizeChange"
        style="margin-top: 16px;"
      ></el-pagination>
    </el-footer>
  </el-container>
</template>

<script>
  /* eslint-disable */
export default {
  name: 'charge-standard-table',
  components: {
  },
  data() {
    return {
      labelPosition: "left",
      pageNum: 1, // 当前页码
      dataCount: 0, // 数据总条数
      dataPageSize: 0, // 每页显示条数
      downloadLoading: false,
      dialogAddVisible: false, // 收费标准Form是否显示
      dialogDetVisible: false, // 收费标准细类是否显示
      detHeadVis: false, // 收费标准细类form头部按钮及多选是否显示
      isCreate: "", // 是否是新增数据
      selectList: [], // 获取的选中行
      chaStaFormData: "", // 向收费标准form传递值
      detList: [], // 收费细类数据
      detStandard: "", // 收费标准名称
      detStandardNo: "" // 收费标准编号
    };
  },
  props: ["loading", "tableDatas"],

  methods: {
    handleCurrentChange: function(val) {
      this.pageNum = val;
    },
    handleSizeChange(val) {
      this.$emit("sizePage", val);
    },
    handleDownloadfinacia() {
      this.downloadLoading = true;
    },
    addData() {
      // 收费标准添加
      this.dialogAddVisible = true;
      this.isCreate = true;
      this.chaStaFormData = {
        standard_no: "", // 收费标准编号
        standard_name: "",
        standard_sdate: "",
        standard_edate: "",
        standard_blur: "",
        standard_free: "",
        useorgs: []
      };
      // this.$refs['chaEditor'].resetForm();
    },
    selectDatas(val) {
      // 通过复选框获取收费标准列表选中多行
      this.selectList = val;
    },
    selectRow(val) {
      // 通过右侧按钮获取收费标准列表选中单行
      this.chaStaFormData = val;
      this.selectList.push(val);
    },
    handleCommand(val) {
      // 收费标准单行编辑
      if (val == "edit") {
        this.dialogAddVisible = true;
        this.isCreate = false;
      } else if (val == "del") {
        this.deleteData();
      }
    },
    editorDetData() {
      // 编辑收费标准细类
      if (this.selectList.length != 1) {
        this.$message({
          type: "warn",
          message: "请选择一条记录进行编辑！",
          duration: 2000
        });
      } else {
        this.dialogDetVisible = true;
        this.detHeadVis = false;
        this.detStandard = this.selectList[0].standard_name;
        this.detStandardNo = this.selectList[0].standard_no;

      }
    },
    addChaStaData(data, val) {
      // 添加/修改成功更新页面
      if (val == 1) {
        this.tableDatas.list.unshift(data);
      } else {
        for (let v of this.tableDatas.list) {
          if (v.standard_no === data.standard_no) {
            const index = this.tableDatas.list.indexOf(v);
            this.tableDatas.list.splice(index, 1, data);
            break;
          }
        }
      }
    },
    dbClick(row, event) {
      // 收费标准列表双击单行

    },
    deleteData() {

    },
    exportData() {
      console.log(444);
    }
  }
};
</script>

<style scoped>
.btn-group > .el-button span {
  display: none;
}
.btn-group > .el-button:hover {
  background-color: #409eff;
}
.btn-group > .el-button:hover span {
  display: block;
}
.btn-group > .el-button:hover i {
  display: none;
}
</style>
